/**
 * @file
 */

#include <cstdint>
#include <boost/filesystem.hpp>
#include "mocha/imported_image_plugin.hpp"
#include "mocha/region.hpp"

using namespace boost::filesystem;

namespace mocha { namespace graphics {
imported_image_plugin::imported_image_plugin(mocha_c_image_plugin* object, mocha_plugin_destroy_func_t destroy): imported_object<mocha_c_image_plugin>(object, destroy) {
}
imported_image_plugin::~imported_image_plugin() {
}
const plugin_char_t* imported_image_plugin::type_name() const {
	return unadapted()->type_name(unadapted());
}
std::int32_t imported_image_plugin::load(const path& file) {
	return unadapted()->load_from_file(unadapted(), reinterpret_cast<const std::int8_t*>(file.string().c_str()));
}
std::int32_t imported_image_plugin::load(std::int8_t* buffer, std::uint32_t size) {
	return unadapted()->load_from_file_buffer(unadapted(), buffer, size);
}
std::int32_t imported_image_plugin::load(std::int8_t* buffer, std::uint32_t width, std::uint32_t height, const pixel_format& format) {
	return unadapted()->load_from_pixels(unadapted(), buffer, width, height, format.mask.red, format.mask.green, format.mask.blue, format.mask.alpha, static_cast<int8_t>(format.type));
}
void imported_image_plugin::free() {
	unadapted()->free(unadapted());
}
std::int32_t imported_image_plugin::crop(const region<int>& region) {
	return unadapted()->crop(unadapted(), region.x, region.y, region.w, region.h);
}
std::int32_t imported_image_plugin::scale(std::uint32_t width, std::uint32_t height) {
	return unadapted()->scale(unadapted(), width, height);
}
std::int32_t imported_image_plugin::convert(const pixel_format& format) {
	return unadapted()->convert(unadapted(), format.mask.red, format.mask.green, format.mask.blue, format.mask.alpha, static_cast<int8_t>(format.type));
}
void imported_image_plugin::pixels(std::int8_t*& buffer, std::uint32_t* out_size) {
	std::uint32_t size;
	unadapted()->read_write_pixels(unadapted(), &buffer, &size);
	*out_size = size;
}
void imported_image_plugin::pixels(std::int8_t const *& buffer, std::uint32_t* out_size) const {
	std::uint32_t size;
	unadapted()->read_pixels(unadapted(), &buffer, &size);
	*out_size = size;
}
std::int32_t imported_image_plugin::format(pixel_format& format) const {
	std::int8_t type;
	std::int32_t r = unadapted()->format(unadapted(), &format.mask.red, &format.mask.green, &format.mask.blue, &format.mask.alpha, &type);
	format.type = static_cast<pixel_data_type>(type);
	return r;
}
std::uint32_t imported_image_plugin::width() const {
	return unadapted()->width(unadapted());
}
std::uint32_t imported_image_plugin::height() const {
	return unadapted()->height(unadapted());
}
std::int8_t imported_image_plugin::loaded() const {
	return unadapted()->loaded(unadapted());
}
}}

